package com.projectsexception.festivales;

import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.projectsexception.festivales.schedule.view.ScheduleViewInflater;
import com.projectsexception.festivales.schedule.view.StagesViewInflater;
import com.projectsexception.festivales.schedule.view.TabScheduleViewInflater;
import com.projectsexception.festivales.setup.ProjectResources;

public class TabScheduleActivity extends Activity {
    
    private Date actualDate;
    private boolean stages = false;
    private TabScheduleViewInflater schedulesInflater;
    private TabScheduleViewInflater stagesInflater;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        schedulesInflater = new ScheduleViewInflater(this);
        stagesInflater = new StagesViewInflater(this);
                
        if (actualDate == null) {
            ProjectResources res = ProjectResources.getInstance(this);
            actualDate = res.getShowDates().get(0);
        }
        changeView();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.tab_schedule_menu, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.tab_schedule_menu_change) {
            String text;
            if (stages) {
                text = getString(R.string.tab_schedule_menu_stages);
            } else {
                text = getString(R.string.tab_schedule_menu_schedule);
            }
            stages = !stages;
            item.setTitle(text);
            changeView();
        }
        return true;
    }
    
    private void changeView() {
        if (stages) {
            stagesInflater.inflateView(actualDate);
        } else {
            schedulesInflater.inflateView(actualDate);
        }
    }

}
